package internal

import (
	"fmt"  // Add fmt package
	"github.com/gin-gonic/gin"
	"log/slog"
	"os"
	"time"
	"vitepress-serve/internal/controller"
)

func Main() {
	slog.Info("*** vitepress serve start...")
	time.Local = time.FixedZone("CST", 8*3600) //时区：东八区

	engine := gin.Default()
	err := controller.Router(engine)
	if err != nil {
		panic(err)
	}
	
	// 获取环境变量中的端口配置
	port := os.Getenv("SERVER_PORT")
	if port == "" {
		port = "8080" // 默认端口
	}
	
	// 启动服务器
	addr := fmt.Sprintf("%s:%s", os.Getenv("SERVER_HOST"), port)
	engine.Run(addr)
}
